#ifndef DVREGIONPOLYGONITEM_H
#define DVREGIONPOLYGONITEM_H

#include <QGraphicsPolygonItem>
#include <QtXml/QDomNode>
#include <QPen>
#include <QBrush>
#include <QFont>

class dvMapScene;
class PolygonTool;

class dvRegionPolygonItem : public QGraphicsPolygonItem
{
public:
    dvRegionPolygonItem(QGraphicsItem *parent = 0);
    ~dvRegionPolygonItem();

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void setPen(const QPen &pen);
    void setBrush(const QBrush &brush);
    bool loadObject(QDomNode node);

    void setChecked(bool state);
    inline bool isChecked(){ return m_checked; }

    inline void setEnabled(bool state){ m_enabled = state; }
    inline bool isEnabled(){ return m_enabled; }

    inline void setMapScene(dvMapScene *scene){ m_pScene = scene; }
    inline dvMapScene* mapScene(){ return m_pScene; }

    void setTextIndicator(const QString& text);

protected:
    QVariant itemChange(GraphicsItemChange change, const QVariant &value);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);

private:
    QPen   m_pen;
    QBrush m_brush;
    QFont  m_font;
    bool   m_checked;
    bool   m_enabled;

    dvMapScene  *m_pScene;
    PolygonTool *m_pTool;
};

class PolygonTool : public QGraphicsItem
{
public:
    PolygonTool(QGraphicsPolygonItem* poly);
    ~PolygonTool();

    QRectF boundingRect() const;
    QPainterPath shape() const;

    void paint(QPainter *painter,
               const QStyleOptionGraphicsItem *option, QWidget *widget);

    void setTextRegion(const QString& text);
    void setTextIndicator(const QString& text);

    void correctContentRect();

protected:
    QRectF outlineRect() const;

private:
    QString m_textRegion;
    QString m_textIndicator;
    QPen    m_pen;
    QBrush  m_brush;
    QFont   m_font;
    QRectF  m_contentRect;
};

#endif // DVREGIONPOLYGONITEM_H







































